function checkSuser() {
	var suser = document.all.suser.value;
	var span = document.getElementById("suserSpanId");
	var regex = /^\w{3,}$/;
	if (!regex.test(suser)) {
		span.innerHTML = "<img src='img/error.png' />用户名必须是英文字母或数字或者下划线并且是3个字符以上！";
		span.style.color = "red";
		return false;
	}
	span.innerHTML = "<img src='img/ok.gif' />";
	span.style.color = "green";
	return true;
}
function checkPswd() {
	var pswd = document.all.pswd.value;
	var span = document.getElementById("pswdSpanId");
	var regex = /^\w{3,}$/;
	if (!regex.test(pswd)) {
		span.innerHTML = "<img src='img/error.png' />请输入长度大于等于3个字符的密码！";
		span.style.color = "red";
		return false;
	}
	span.innerHTML = "<img src='img/ok.gif'/>";
	span.style.color = "green";
	return true;
}

function checkConfPswd() {
	var pswd = document.all.pswd.value;
	var confPswd = document.all.confPswd.value;
	var span = document.getElementById("confPswdSpanId");
	if (pswd == "") {
		span.innerHTML = "<img src='img/error.png' />密码不能为空！";
		span.style.color = "red";
		return false;
	}
	if (confPswd == "") {
		span.innerHTML = "<img src='img/error.png' />确认密码不能为空！";
		span.style.color = "red";
		return false;
	}
	if (confPswd != pswd) {
		span.innerHTML = "<img src='img/error.png' />密码必须一致";
		span.style.color = "red";
		return false;
	}
	span.innerHTML = "<img src='img/ok.gif' />";
	span.style.color = "green";
	return true;
}

function checkSname() {
	var sname = document.all.sname.value;
	var span = document.getElementById("snameSpanId");
	var regx = /^\w{1,15}/;
	if (!regx.test(sname)) {
		span.innerHTML = "<img src='img/error.png' />请输入姓名，长度小于15！";
		span.style.color = "red";
		return false;
	}
	span.innerHTML = "<img src='img/ok.gif' />";
	span.style.color = "green";
	return true;
}
function checkSsex() {
	var ssex = document.getElementsByName("ssex");
	var span = document.getElementById("ssexSpanId");
	for (var i = 0; i < ssex.length; i++) {
		if (ssex[i].checked) {
			span.innerHTML = "<img src='img/ok.gif' />";
			span.style.color = "green";
			return true;
		}
	}
	span.innerHTML = "<img src='img/error.png' />请选择性别";
	span.style.color = "red";
	return false;
}

function checkDbrith() {
	var dbrith = document.all.dbrith.value;
	alert(dbrith + "hah");
	var span = document.getElementById("dbrithSpanId");
	if (dbrith == "") {
		span.innerHTML = "<img src='img/error.png' />出生日期不能为空！";
		span.style.color = "red";
		return false;
	}
	span.innerHTML = "<img src='img/ok.gif' />";
	span.style.color = "green";
	return true;
}

function checkSemail() {
	var semail = document.all.semail.value;
	var span = document.getElementById("semailSpanId");
	regx = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
	if (!regx.test(semail)) {
		span.innerHTML = "<img src='img/error.png '/>请输入正确的邮箱！";
		span.style.color = "red";
		return false;
	}
	span.innerHTML = "<img src='img/ok.gif' />";
	span.style.color = "green";
	return true;
}

function checkSphone() {
	var sphone = document.all.sphone.value;
	var span = document.getElementById("sphoneSpanId");
	var s = /^\d{11}$/;

	if (!s.test(sphone)) {
		span.innerHTML = "<img src='img/error.png' />请输入正确的电话号码";
		span.style.color = "red";
		return false;
	}
	span.innerHTML = "<img src='img/ok.gif' />";
	span.style.color = "green";
	return true;
}

function checkSaddress() {
	var saddress = document.all.saddress.value;
	var span = document.getElementById("saddressSpanId");
	regx = /^\w{1,100}$/;
	if (!regx.test(saddress)) {
		span.innerHTML = "<img src='img/error.png' />输入地址长度小于100";
		span.style.color = "red";
		return false;
	}

	span.innerHTML = "<img src='img/ok.gif' />";
	span.style.color = "green";
	return true;
}

function checkScode() {
	var scode = document.all.scode.value;
	var span = document.getElementById("scodeSpanId");
	var s = /^\d{6}$/;
	if (!s.test(scode)) {
		span.innerHTML = "<img src='img/error.png' />请6位数字的邮箱";
		span.style.color = "red";
		return false;
	}
	span.innerHTML = "<img src='img/ok.gif' />";
	span.style.color = "green";
	return true;
}

function checkForm() {
	var suserFlag = checkSuser();
	var pswdFlag = checkPswd();
	var confPswdFlag = checkConfPswd();
	var snameFlag = checkSname();
	var ssexFlag = checkSsex();
	var dbirthFlag = checkDbrith();
	var semailFlag = checkSemail();
	var sphoneFlag = checkSphone();
	var saddressFlag = checkSaddress();
	var scodeFlag = checkScode();
	alert(snameFlag);
	var flag = suserFlag && pswdFlag && confPswdFlag && snameFlag && ssexFlag
			&& dbirthFlag && semailFlag && sphoneFlag && saddressFlag
			&& scodeFlag;
	alert(flag);
	return flag;
}